<div class="header_menu">
    <div class="container">
        <div class="header-nav clearfix">
            <?php echo $this->partial('shop/layout/headerMenu'); ?>
        </div>
    </div>
</div>
</div>

<div class="container">
    <!--S cart-->
    <div id="shopCartBox">
        <div class="shop-cart-box">
            <div class="shop-cart-box-hd">
                <h2 class="title"><?php echo $this->translate('我的购物车'); ?></h2>
            </div>
            <?php echo $this->partial('shop/message'); ?>
            <?php if ($this->cartGoodsList) { ?>
                <div class="shop-cart-box-bd shop-cart-goods">
                    <!--  购物车商品列表 -->
                    <table>
                        <thead>
                        <tr>
                            <th width="5%">
                                <input type="checkbox" <?php if($this->haveGoodsChecked) echo 'checked'; ?> id="checkbox-all">
                                <label for="checkbox-all"></label>
                            </th>
                            <th width="30%"><?php echo $this->translate('商品'); ?></th>
                            <th width="12%"><?php echo $this->translate('货号'); ?></th>
                            <th width="15%"><?php echo $this->translate('规格'); ?></th>
                            <th width="10%"><?php echo $this->translate('数量'); ?></th>
                            <th width="10%"><?php echo $this->translate('价格'); ?></th>
                            <th width="10%"><?php echo $this->translate('总价'); ?></th>
                            <th width="5%"><?php echo $this->translate('操作'); ?></th>
                        </tr>
                        </thead>
                        <?php foreach ($this->cartGoodsList as $goodsValue) { ?>
                            <tr>
                                <td>
                                    <?php if($goodsValue['goodsState'] == 1 && !$goodsValue['goodsStockOut']) { ?>
                                        <div class="cart-select">
                                            <input type="checkbox" value="<?php echo $goodsValue[0]->getCartId(); ?>" id="checkbox-<?php echo $goodsValue[0]->getCartId(); ?>" <?php if($goodsValue[0]->getGoodsChecked() == 1) echo 'checked'; ?> name="selected[]" onchange="cartSelect(<?php echo $goodsValue[0]->getCartId(); ?>);">
                                            <label for="checkbox-<?php echo $goodsValue[0]->getCartId(); ?>"></label>
                                        </div>
                                    <?php } else { ?>
                                        <span class="label label-default"><?php echo $this->translate('失效'); ?></span>
                                    <?php } ?>
                                </td>
                                <td>
                                    <a href="<?php echo $this->url('shop-goods', ['id' => $goodsValue[0]->getGoodsId()]); ?>"><img src="<?php echo $this->shopHelper()->baseGoodsImagePath($goodsValue['goodsThumbnailImage']); ?>"  style=" height:65px;width:65px;border:1px solid #D7D7D7">&nbsp;&nbsp;<?php echo $this->escapeHtml($goodsValue['goodsName']); ?></a>
                                </td>
                                <td><?php echo $this->escapeHtml($goodsValue['goodsItem']); ?></td>
                                <td>
                                    <?php if(isset($goodsValue['specGoodsTagInfo'])) { ?>
                                        <?php foreach ($goodsValue['specGoodsTagInfo'] as $specInfo) { ?>
                                            <small><?php echo $this->escapeHtml($specInfo['tagGroupName']); ?>：<?php echo $this->escapeHtml($specInfo[0]->getTagName()); ?></small>
                                        <?php } ?>
                                    <?php } ?>
                                </td>
                                <td>
                                    <div id="cart-product-quantity" class="input-group">
                                        <?php if($goodsValue['goodsState'] == 1 && !$goodsValue['goodsStockOut']) { ?>
                                            <span class="input-group-btn quantity-down"><button class="btn btn-primary" type="button">-</button></span>
                                            <input type="text" name="buyNum" data-id="<?php echo $goodsValue[0]->getCartId(); ?>" value="<?php echo $goodsValue[0]->getBuyNum(); ?>" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width: 30px;height: 16px;" class="cart-input-quantity">
                                            <span class="input-group-btn quantity-up"><button class="btn btn-primary" type="button">+</button></span>
                                        <?php } else echo $goodsValue[0]->getBuyNum(); ?>
                                    </div>
                                </td>
                                <td>
                                    <?php echo $this->frontCurrency($goodsValue['goodsPrice']); ?>
                                </td>
                                <td>
                                    <?php echo $this->translate('总计'); ?>：<?php echo $this->frontCurrency($goodsValue['goodsAmount']); ?>
                                </td>
                                <td><a href="javascript:;" onclick="deleteNotConfirm('<?php echo $this->url('shop-cart', ['action' => 'deleteCartGoods', 'id' => $goodsValue[0]->getCartId()]); ?>', '');"><?php echo $this->translate('删除'); ?></a></td>
                            </tr>
                        <?php } ?>
                    </table>
                </div>
                <div class="shop-cart-box-ft clearfix">
                    <div class="shop-cart-total">
                <span class="pull-right" style="text-align:right;">
                    <strong><?php echo $this->translate('应付总额'); ?>（<font color="#139EE6"><?php echo $this->translate('不含运费'); ?></font>）：<font size="5" color="#ff4a00"><?php echo $this->frontCurrency($this->cartAmount); ?></font></strong>
                </span>
                    </div>
                    <div class="shop-cart-action clearfix">
                        <a class="btn btn-primary btn-next" href="<?php echo $this->url('shop-checkout'); ?>"><?php echo $this->translate('去结算'); ?></a>
                        <a class="btn btn-lineDakeLight btn-back" href="<?php echo $this->url('shop'); ?>"><?php echo $this->translate('继续去购物'); ?></a>
                        <div class="tips">
                            <span class="shop-cart-coudan"><a href="javascript:;" onclick="deleteNotConfirm('<?php echo $this->url('shop-cart', ['action' => 'clearCartGoods']); ?>', '');"><i class="iconfont"></i> <?php echo $this->translate('清空购物车'); ?></a></span>
                        </div>
                    </div>
                </div>

                <script>
                    var initQuantity;
                    $(document).on('click', '#cart-product-quantity input', function(event) {
                        initQuantity = $(this).val();
                    });

                    $(document).on('blur', '#cart-product-quantity input', function(event) {
                        if ( initQuantity == $(this).val() ) return;
                        cartUpdate($(this).attr('data-id'), $(this).val());
                    });

                    $(document).on('click', '#cart-product-quantity span', function(event) {
                        event.preventDefault();
                        var _qtyInput = $(this).siblings('.cart-input-quantity');
                        if( $(this).hasClass('quantity-up')) {
                            _qtyInput.val(_qtyInput.val() * 1 + 1);
                        } else {
                            if ( _qtyInput.val() == 1 ) return;
                            _qtyInput.val(_qtyInput.val() - 1);
                        }
                        cartUpdate(_qtyInput.attr('data-id'), _qtyInput.val());
                    });

                    var cartUpdate = function(cartId, buyNum) {
                        $.ajax({
                            url: '<?php echo $this->url('shop-cart', ['action' => 'editCartGoodsNum']); ?>',
                            type: 'post',
                            dataType: 'json',
                            data: {cartId:cartId, buyNum:buyNum},
                            success: function (data) {
                                if(data.status != 'true') {
                                    showMessage(data.message);
                                }
                                layer.load(2, {shade: [0.05, '#000'] });
                                window.location.href="<?php echo $this->url('shop-cart'); ?>";
                            }
                        });
                    }

                    function cartSelect(cartId) {
                        $.ajax({
                            url: "<?php echo $this->url('shop-cart', ['action' => 'changeCartGoodsSelected']); ?>",
                            type: 'post',
                            dataType: 'json',
                            data: {cartId:cartId},
                            success: function(data) {
                                if(data.status != 'true') {
                                    showMessage(data.message);
                                } else {
                                    layer.load(2, {shade: [0.05, '#000'] });
                                    window.location.reload();
                                }
                            }
                        });
                    }
                    $(document).on('click', '#checkbox-all', function(event) {
                        $('input[name*=\'selected\']').prop('checked', this.checked);
                        $.ajax({
                            url: "<?php echo $this->url('shop-cart', ['action' => 'changeAllCartGoodsSelected']); ?>",
                            type: 'post',
                            dataType: 'json',
                            data: {checkState:this.checked},
                            success: function(data) {
                                if(data.status != 'true') {
                                    showMessage(data.message);
                                } else {
                                    layer.load(2, {shade: [0.05, '#000'] });
                                    window.location.reload();
                                }
                            }
                        });
                    });
                </script>

            <?php } else { ?>
                <p><h3><?php echo $this->translate('您的购物车中没有商品，赶快去挑选您中意的商品吧!'); ?></h3></p>
                <input type="button" class="btn btn-primary" onclick="window.location.href='<?php echo $this->url('shop'); ?>'" value="<?php echo $this->translate('点击去商城首页购物'); ?>">
            <?php } ?>
        </div>
    </div>
</div>
<?php
if($this->cartIndexPartial) foreach ($this->cartIndexPartial as $partialValue) {
    echo $this->partial($partialValue['partialFile'], $partialValue['partialArg']);
}
?>